<?php

namespace app\home\controller;

use think\Controller;
use think\facade\Request;


use think\facade\Session;
class Account extends Base
{
   
    public function index()
    {
        //
        return view();
    }


    public function myorder()
    {
        // $id=input()['id'];
        // $goods_id=input()['id'];
        $ordergoods=\app\common\model\OrderGoods::select();
        

        
        return view('myorder',['ordergoods'=>$ordergoods]);
    }
    public function address()
    {
       
        
         $address=\app\common\model\Address::select();
        
        return view('address',['address'=>$address]);
    }

    public function addaddress()
    {
       
        
         $address=\app\common\model\Address::select();
        
        return view('addaddress',['address'=>$address]);
    }

    public function add()
    {
       
        $param=Request::param();
        $user_id=session('user_info.id');
        $data=[
            'user_id'=>$user_id,
            'consignee'=>$param['consignee'],
            'area'=>$param['area'],
            'address'=>$param['address'],
            'phone'=>$param['phone']

        ];
         \app\common\model\Address::create($data,true);

        
        $this->redirect('home/account/address');
    }

    public function addelete($id){
        // dump($id);die;
        \app\common\model\Address::where('id',$id)->delete();
        $this->redirect('home/account/address');
    }


public function personal(){
        // dump($id);die;
        // $user=\app\common\model\User::where
        $user_id=session('user_info.id');
        $user_phone=session('user_info.phone');
        $user_password=session('user_info.password');
        $user_nickname=session('user_info.nickname');
        $data=[
            'user_id'=>$user_id,
            'nickname'=>$user_nickname,
            'user_phone'=>$user_phone,
            'user_password'=>$user_password,
            

        ];

        return view('personal',['data'=>$data]);
    }
    public function addpersonal(){
        $param=input()['id'];
        return view('addpersonal',['id'=>$param]);
    }

    public function addp($id){
        $param=Request::param();
        // dump($data);die;
        $user_nickname=session('user_info.nickname');
        $data=[
            
            'nickname'=>$param['nickname'],

        ];
        \app\common\model\User::where('id',$id)->update($data);
        session('user_info.nickname',$data['nickname']);
        $this->redirect('home/account/personal');

    }

    public function addm(){
        $param=input()['id'];
        return view('addm',['id'=>$param]);
    }

    public function addmi($id){
        $param=Request::param();
        // dump($data);die;
        $user_nickname=session('user_info.password');
        $data=[
            
            'password'=>$param['password'],

        ];
        \app\common\model\User::where('id',$id)->update($data);
        session('user_info.password',$data['password']);
        $this->redirect('home/account/personal');
    }


}
